package com.woniu.controller;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.controller.form.GetByTimeForm;
import com.woniu.model.Inventory;
import com.woniu.model.JunkType;
import com.woniu.model.Result;
import com.woniu.service.InventoryService;
import com.woniu.service.param.GetByTimeParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  垃圾入库相关接口
 * </p>
 *
 * @author 吴彦祖
 * @since 2024年05月23日
 */
@RestController
@Api(tags = "垃圾入库相关接口")
@RequestMapping("/inventory")
public class InventoryController {

    @Resource
    private InventoryService inventoryService;

    /**
     * 根据订单号查询入库详情
     * id 订单号(orderNum 懒得改名字了 所以写成id)
     */
    @GetMapping("/getById/{id}")
    @ApiOperation("根据id查找入库详情")
    public Result<Inventory> getByOrderId(@PathVariable("id") String id) throws Exception {
        Inventory inventory = inventoryService.getByOrderId(id);
        return Result.newInstance(Inventory.class).setCode(200).setData(inventory).setMessage("根据id查找入库详情成功!");
    }


    /**
     * 根据站点id查询入库详情
     * id 站点id
     */
    @GetMapping("/getByStationId")
    @ApiOperation("根据站点id查询入库详情")
    public Result<Page<Inventory>> getByStationId(@RequestParam("id") Integer id,@RequestParam("pageNum") Integer pageNum,@RequestParam("pageSize") Integer pageSize) throws Exception {
        Page<Inventory> inventory = inventoryService.getByStationId(id,pageNum,pageSize);
        return Result.newPageInstance(Inventory.class).setCode(200).setData(inventory).setMessage("根据站点id查询入库详情成功!");
    }

    /**
     * 根据时间查询某站点入库详情
     * id 站点id
     */
    @PostMapping("/getByTime")
    @ApiOperation("根据时间查询某站点入库详情")
    public Result<Page<Inventory>> getByTime(@RequestBody GetByTimeForm form) throws Exception {
        Page<Inventory> inventory = inventoryService.getByTime(BeanUtil.toBean(form, GetByTimeParam.class));
        return Result.newPageInstance(Inventory.class).setCode(200).setData(inventory).setMessage("根据时间查询某站点入库详情成功!");
    }


}

